package com.mango.leet.code.week1.game388;

import java.util.Arrays;

/**
 * https://leetcode.cn/contest/weekly-contest-388/problems/apple-redistribution-into-boxes/
 * @Author: mango
 * @Date: 2024/3/10 11:06
 */
public class LC100233 {

    public int minimumBoxes(int[] apple, int[] capacity) {
        int sum = Arrays.stream(apple).sum();
        Arrays.sort(capacity);
        int result = 1;
        int cSum = capacity[capacity.length-1];
        for (int i = capacity.length - 2; i >= 0 ; i--) {
            if (cSum >= sum) {
                break;
            }
            cSum += capacity[i];
            result++;
        }
        return result;
    }
}
